package com.hjs.servlet.dailyinspection.dailyinspectrecording;

import com.hjs.bean.DailyInspecteRecordingCom;
import com.hjs.mapper.DailyInspectRecordingMapper;
import com.hjs.tools.Mapper;
import com.hjs.tools.RequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author violetfreesia
 * @date 2020/06/19
 */
@Slf4j
@WebServlet("/dailyInspection/update")
public class UpdateDailyInspection extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        RequestUtil requestUtil = new RequestUtil(request, response);
        try (SqlSession sqlSession = Mapper.getSqlSession()) {
            DailyInspecteRecordingCom dailyInspecteRecordingCom = new DailyInspecteRecordingCom(requestUtil.getInt("dailyInspecteRecordingComID"),
                    null, requestUtil.getInt("damageTypeID"),
                    requestUtil.getString("damageDescription"), requestUtil.getString("remarks"));
            DailyInspectRecordingMapper mapper = sqlSession.getMapper(DailyInspectRecordingMapper.class);
            boolean sqlResult  = mapper.updateOneDailyInspecteRecordingCom(dailyInspecteRecordingCom);
            Mapper.SessionEnd(sqlResult, sqlSession);
            requestUtil.responseIsSuccess(sqlResult,"更新日常巡检记录失败");
        } catch (Exception e) {
            log.error(e.toString());
            requestUtil.responseFail("未知错误");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    }
}
